
<template>
  <div>
    <!-- 日志管理页面 -->
    <div>
      <el-table
        size="mini"
        v-loading="loading"
        stripe
        :data="tableData"
        style="width: 100%"
      >
        <el-table-column type="index" align="center" label="序号"> </el-table-column>
        <el-table-column align="center" prop="realname" label="访问人真实姓名">
        </el-table-column>
        <el-table-column align="center" prop="method" label="访问方式">
        </el-table-column>
        <el-table-column align="center" prop="content" label="访问路径">
        </el-table-column>
        <el-table-column align="center" label="访问时间">
          <template slot-scope="scope">{{
            moment(scope.logTime).format("YYYY-MM-DD hh:mm:ss")
          }}</template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="pagination-div">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.page"
        :page-sizes="[5, 10, 15, 20, 30]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { pageQuery } from "@/api/log";
import moment from "moment";

export default {
  data() {
    return {
      tableData: [],
      // 分页参数
      params: {
        page: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
    };
  },
  watch: {
    // 深度监听分页参数
    params: {
      handler() {
        this.queryData();
      },
      deep: true,
    },
  },
  computed: {},
  methods: {
    moment,
    async queryData() {
      this.loading = true;
      let temp = {
        ...this.params,
      };

      // 遍历对象
      for (let key in temp) {
        if (!temp[key]) {
          delete temp[key];
        }
      }
      let res = await pageQuery(temp);
      // 加载完毕
      this.loading = false;
      this.tableData = res.data.list;
      this.total = res.data.total;
    },
    // 时间格式化
    // 每页显示的条数发生变化时的事件处理程序
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      // this.params.pageSize = val;
      // this.params.page = 1;
      this.params = {
        page: 1,
        pageSize: val,
      };
      //this.queryData()
    },
    // 当前页码发生变化时的事件处理程序
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.params.page = val;
      //this.queryData()
    },
  },
  created() {
    this.queryData();
  },
  mounted() {},
};
</script>
<style scoped>
</style>